package com.example.neusoft215gdh.androidpro_21.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft215gdh.androidpro_21.JavaBean.PeiXunDetail;
import com.example.neusoft215gdh.androidpro_21.Listener.PeiXunDetailListener;
import com.example.neusoft215gdh.androidpro_21.Model.PeiXunModel;
import com.example.neusoft215gdh.androidpro_21.R;
import com.squareup.picasso.Picasso;

/**
 * Created by hp-pc on 2017/10/9.
 */
public class PeiXunDetailActivity extends AppCompatActivity implements PeiXunDetailListener ,View.OnClickListener{

    private ImageView img;
    private TextView name;
    private TextView intro;
    private TextView notice;
    private TextView time;
    private Button baoming;
    Intent intent;
    public  String Picid;
    public int id;
    public PeiXunDetail list;
    String userid;
    private  String  BMPrice;//价格
    private String   peixunname;//培训名字
    private String bmnotice;//报名须知
    private String user_id;//用户id
    private  String Train_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.train_detail);
        SharedPreferences user=getSharedPreferences("Userid",0);
        userid=user.getString("user_id","");
        intent=getIntent();
        Picid=intent.getStringExtra("id");
        PeiXunModel peiXunModel=new PeiXunModel();
        peiXunModel.getPeiXunDetailList(userid,Picid,this);
        initViews();
       baoming.setOnClickListener(this);
    }

    public void initViews() {

         img= (ImageView) findViewById(R.id.peiXun_img);
        intro= (TextView) findViewById(R.id.train_intro);
         notice= (TextView) findViewById(R.id.courseNotice);
        time= (TextView) findViewById(R.id.Time);
        baoming= (Button) findViewById(R.id.baoming);
    }

    @Override
    public void onResponse(PeiXunDetail bean) {
       list=bean;
      intro.setText(list.getIntro());
       notice.setText(list.getNotice());
        time.setText(list.getUpdate_time());
        if(!list.getThumb().isEmpty())
        {
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+list.getThumb()).into(img);
        }
        else
        {
         img.setImageResource(R.drawable.ic_person);
        }
        BMPrice=list.getPrice();
        bmnotice=list.getBmnotice();
        user_id=list.getUserid();
        Train_id=list.getId();
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.baoming:
                Intent intent=new Intent(com.example.neusoft215gdh.androidpro_21.Activity.PeiXunDetailActivity.this, com.example.neusoft215gdh.androidpro_21.Activity.PayActivity.class);
                intent.putExtra("peixunmane", peixunname);
                intent.putExtra("bmPrice", BMPrice);
                intent.putExtra("bmnotice", bmnotice);
                intent.putExtra("userid", userid);
                intent.putExtra("Train_id", Train_id);
                startActivity(intent);
                break;
        }
    }
}
